// $Id$
// Licensed under Apache License Version 2.0
// See: http://www.apache.org/licenses/LICENSE-2.0.html
package de.servicezombie.errors;

public class ReadableIdentity {
	
	private Class<?> sourceType;
	private Object sourceId;
	private ReadableIdentity parent;
	
	/**
	 * 
	 * @param parent may be null to indicate root node
	 * @param sourceType usually <em>caller.getClass()</em>
	 * @param sourceId optional id. may be null.
	 */
	public ReadableIdentity(Class<?> sourceType, Object sourceId, ReadableIdentity parent) {
		super();
		this.sourceType = sourceType;
		this.sourceId = sourceId;
		this.parent = parent;
	}
	
	/**
	 * @see #ReadableIdentity(Class, Object, ReadableIdentity)
	 */
	public ReadableIdentity(Class<?> sourceType, Object sourceId) {
		this(sourceType, sourceId, null);
	}

	/**
	 * @see #ReadableIdentity(Class, Object, ReadableIdentity)
	 */
	public ReadableIdentity(Class<?> sourceType) {
		this(sourceType, null, null);
	}
		
	@Override
	public String toString() {
		final String idSuffix = sourceId != null ? "$" + sourceId : "";
		final String myId = sourceType.getSimpleName() + idSuffix;
		return parent != null ? parent + "." + myId : myId; 
	}

}
